package cn.psvmc.cxzapi.service.system;

import cn.psvmc.cxzapi.config.mybatisplus.service.impl.AbstractService;
import cn.psvmc.cxzapi.mapper.system.TPlatformSetMapper;
import cn.psvmc.cxzapi.model.system.TPlatformSet;
import cn.psvmc.cxzapi.util.ToolUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 平台配置表 服务实现类
 * @Author auto
 * @Date 2024-08-15
 */
@Service
public class TPlatformSetService extends AbstractService<TPlatformSetMapper, TPlatformSet> {

    @Resource
    private TPlatformSetMapper tPlatformSetMapper;

    /**
    * @Date auto 2024-08-15 新增平台配置表
    * @Param tPlatformSet 平台配置表
    * @Return int
    */
    public int add(TPlatformSet tPlatformSet){
        return tPlatformSetMapper.insert(tPlatformSet);
    }

    /**
    * @Date auto 2024-08-15 更新平台配置表
    * @Param tPlatformSet 平台配置表模型
    * @Return int
    */
    public int edit(TPlatformSet tPlatformSet) {
        Map<String, Object> detail = detail();
        if (detail == null) {
            return add(tPlatformSet);
        }
        tPlatformSet.setPsid(ToolUtils.objToInteger(detail.get("psid")));

        // 字段为null 不更新
        return tPlatformSetMapper.updateById(tPlatformSet);
    }

    /**
     * @Description 平台配置详情
     * @Date 2024/8/15 21:02
     * @Author YWX
     * @Param []
     * @Return java.util.Map<java.lang.String,java.lang.Object>
     **/
    public Map<String,Object> detail() {
        return tPlatformSetMapper.getDetail();
    }
}
